﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

namespace ProjectStudy
{
    public partial class LoginTest : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (username.Text == "cxf" && pwd.Text == "123")
            {
                Session["username"] = username.Text;

                Hashtable hOnline = (Hashtable)Application["Online"];
                if (hOnline != null)
                {
                    int i = 0;
                    while (i < hOnline.Count) //因小BUG所以增加此判断，强制查询到底
                    {
                        IDictionaryEnumerator idE = hOnline.GetEnumerator();
                        string strKey = "";
                        while (idE.MoveNext())
                        {
                            if (idE.Value != null && idE.Value.ToString().Equals(username.Text))
                            {
                                strKey = idE.Key.ToString();
                                hOnline[strKey] = "XXXXXX";
                                break;
                            }
                        }
                        i = i + 1;
                    }
                }
                else
                {
                    hOnline = new Hashtable();
                }
                hOnline[Session.SessionID] = username.Text;
                Application.Lock();
                Application["Online"] = hOnline;
                Application.UnLock();

                Response.Redirect("强制用户下线1.aspx");
            }
        }
    }
}